package tt.dz.appaction;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import tt.dz.appaction.base.BaseController;
import tt.dz.common.Constants;
import tt.dz.common.PublicFunc;
import tt.dz.entity.UserRechargeBill;
import tt.dz.service.UserRechargeService;



/**
 * 充值业务控制
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/userRecharge")
public class UserRechargeBillController extends BaseController {

	/**充值业务接口*/
	@Resource
	UserRechargeService rechargeService;
	
	/**
	 * 添加一个充值订单
	 * @param userRechargeBill 充值订单对象
	 * @param request
	 * @param response
	 */
	@RequestMapping("/recharged.do")
	public void recharge(UserRechargeBill userRechargeBill, HttpServletRequest request,HttpServletResponse response){
		
		String resultStr = "";
		try {
			/**用户充值*/
			String code = rechargeService.userRecharge(userRechargeBill);
			resultStr = PublicFunc.getOutStr(code, "ok", null);
		} catch (Exception e) {
			e.printStackTrace();
			resultStr = PublicFunc.getOutStr(Constants.JsonResponseCode.DATABASE_OP_ERROR, e.getMessage(), null);
		}
		this.outText(resultStr, response);
	}
	
	/**
	 * 完成订单
	 * @param recharge_id
	 * @param response
	 */
	@RequestMapping("/finishRechargeBill.do")
	public void finishRechargeBill(String alipayTradeNum,Integer userId,HttpServletResponse response){
		
		String resultStr = "";
		try {
			/**用户充值*/
			String code = rechargeService.finishRechargeBill(alipayTradeNum,userId);
			resultStr = PublicFunc.getOutStr(code, "ok", null);
		} catch (Exception e) {
			e.printStackTrace();
			resultStr = PublicFunc.getOutStr(Constants.JsonResponseCode.DATABASE_OP_ERROR, e.getMessage(), null);
		}
		this.outText(resultStr, response);
		
	}
	
}












